package com.zynn.service.module.calculate.controller;

import com.zynn.common.pojo.result.Result;
import com.zynn.common.pojo.result.ResultUtil;
import com.zynn.service.module.calculate.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author liqi
 *
 */
@RestController
@RequestMapping("/pay")
public class PayController {

    Map<String, PayService> pays;

    @Autowired
    private List<PayService> lists;


    public void init(String type){

        pays = lists.stream().collect(Collectors.toMap(PayService::getType,e->e));

    }


    @RequestMapping("/test")
    public Result initPayService(@RequestParam("type")String type) {

        init(type);
        PayService payService =  pays.get(type);
        payService.methodA();
        payService.methodB();
        return ResultUtil.success();
    }
}
